//
//  AddViewController.m
//  08-tableView-student
//
//  Created by 王道林 on 16/7/25.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "AddViewController.h"




@interface AddViewController ()
@property (nonatomic, strong) UITextField *textFieldAge;
@property (nonatomic, strong) UITextField *textFieldGender;
@property (nonatomic, strong) UITextField *textFieldName;
@property (nonatomic, strong) UITextField *textFieldPhoneNumber;


@end

@implementation AddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    [self createSubview];
}

- (void)createSubview
{
    
    self.textFieldAge = [[UITextField alloc] initWithFrame:CGRectMake(100, 50, 200, 50)];
    _textFieldAge.backgroundColor = [UIColor grayColor];
    [self.view addSubview:_textFieldAge];
    _textFieldAge.placeholder = @"age";
    
    self.textFieldGender = [[UITextField alloc] initWithFrame:CGRectMake(100, 150, 200, 50)];
    _textFieldGender.backgroundColor = [UIColor grayColor];
    [self.view addSubview:_textFieldGender];
    _textFieldGender.placeholder = @"gender";
    
    self.textFieldName = [[UITextField alloc] initWithFrame:CGRectMake(100, 250, 200, 50)];
    _textFieldName.backgroundColor = [UIColor grayColor];
    [self.view addSubview:_textFieldName];
    _textFieldName.placeholder = @"name";
    
    self.textFieldPhoneNumber = [[UITextField alloc] initWithFrame:CGRectMake(100, 350, 200, 50)];
    _textFieldPhoneNumber.backgroundColor = [UIColor grayColor];
    [self.view addSubview:_textFieldPhoneNumber];
    _textFieldPhoneNumber.placeholder = @"phoneNumber";
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor blueColor];
    button.frame = CGRectMake(200, 500, 50, 50);
    button.titleLabel.text = @"完成";
    [self.view addSubview:button];
    [button addTarget:self action:@selector(completeButton:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)completeButton:(UIButton *)button
{
    if (![_textFieldName.text isEqualToString:@""]) {
        
        NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:_textFieldAge.text, @"age", _textFieldGender.text, @"gender", _textFieldName.text, @"name", _textFieldPhoneNumber.text, @"phoneNumber",nil];
        
        [self.delegate passDictionary:dic];
        [self.navigationController popViewControllerAnimated:YES];
    } else
    {
        NSLog(@"请输入姓名");
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
